package com.example.mes_boot.controller;

import com.example.mes_boot.pojo.checkpoint;
import com.example.mes_boot.pojo.project;
import com.example.mes_boot.service.Indexservice;
import com.example.mes_boot.service.imp.addservieimpl;
import com.example.mes_boot.service.imp.deleservieimpl;
import com.example.mes_boot.service.imp.updataservieimpl;
import org.apache.ibatis.session.RowBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/project")
public class projectcontroller {
    @Autowired
    private Indexservice indexservice;
    @Autowired
    private updataservieimpl updataservieimpl;
    @Autowired
    private deleservieimpl deleservieimpl;
    @Autowired
    private addservieimpl addservieimpl;
    //加载接口
    @PostMapping("/load")
    private List<project> findproject(){
        return indexservice.findByproject();
    }
    //分页接口
    @PostMapping("/page")
    private List<project> findby(@RequestBody project point) {
        int currPage=point.getPage();//当前页码
        int pageSize=8;//当前页显示记录数量
        //注意：currPage和start别搞错了，一个表示当前页码，一个是从第几行读取记录
        int start = (currPage-1)*pageSize;//计算从第几行读取记录
        RowBounds rowBounds = new RowBounds(start,pageSize);
        return indexservice.findByprojectpage(rowBounds);
    }
//    修改接口
    @PostMapping("/updata")
    private  void updata(@RequestBody project updata){
       updataservieimpl.projectup(updata.getId(),updata.getName(),updata.getLeader(),updata.getStart_date(),updata.getEnd_date(),updata.getStatus());

    }
    //新增接口
    @PostMapping("/add")
    private  void add(@RequestBody project add){
        addservieimpl.addproject(add);
    }
    //删除接口
    @PostMapping("/dele")
    private void dele(@RequestBody project oid ){
        deleservieimpl.deleproject(oid.getId());
    }
    //查找接口
    @PostMapping("/sele")
    private List<project> sele(@RequestBody project sele){
        System.out.println(sele);
        return indexservice.findBylike(sele.getName(),sele.getStart_date(),sele.getEnd_date(),sele.getStatus());
    }

}
